import math

max = 0
a = int(input())
b = str(a)
c = len(b)
if c == 4:
    w = b[0] + b[1]
    q = int(w)
    for k in range(2,int(math.sqrt(q) + 1)):
        if q % k == 0:
            break
    else:
        c1 = q
    e = b[1] + b[2]
    r = int(e)
    for k in range(2,int(math.sqrt(r) + 1)):
        if r % k == 0:
            break
    else:
        c2 = r
        if c1 > c2:
            max = c1
        else:
            max = c2
    t = b[2] + b[3]
    y = int(t)
    for k in range(2,int(math.sqrt(y) + 1)):
        if y % k == 0:
            break
    else:
        c3 = y
        if c3 > max:
            max = c3
        else:
            max = max
    u = b[0] + b[1] + b[2]
    i = int(u)
    for k in range(2,int(math.sqrt(i) + 1)):
        if i % k == 0:
            break
    else:
        c4 = i
        if c4 > max:
            max = c4
        else:
            max = max
    o = b[1] + b[2] + b[3]
    p = int(o)
    for k in range(2,int(math.sqrt(p) + 1)):
        if p % k == 0:
            break
    else:
        c5 = p
        if c5 > max:
            max = c5
        else:
            max = max
    s = b[0]
    d = int(s)
    for k in range(2,int(math.sqrt(d) + 1)):
        if d % k == 0:
            break
    else:
        c6 = d
        if c6 > max:
            max = c6
        else:
            max = max
    f = b[1]
    g = int(f)
    for k in range(2,int(math.sqrt(g) + 1)):
        if g % k == 0:
            break
    else:
        c7 = g
        if c7 > max:
            max = c7
        else:
            max = max
    h = b[2]
    j = int(h)
    for k in range(2,int(math.sqrt(j) + 1)):
        if j % k == 0:
            break
    else:
        c8 = j
        if c8 > max:
            max = c8
        else:
            max = max
    l = b[3]
    z = int(l)
    for k in range(2,int(math.sqrt(z) + 1)):
        if z % k == 0:
            break
    else:
        c9 = z
        if c9 > max:
            max = c9
        else:
            max = max
    n = b[0] + b[1] + b[2] + b[3]
    m = int(n)
    for k in range(2,int(math.sqrt(m) + 1)):
        if m % k == 0:
            break
    else:
        c10 = m
        if c10 > max:
            max = c10
        else:
            max = max
    print(max)
else:
    print('0')